package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.pojo.DishFlavor;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishSelectIdVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController("adminDishController")
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {

    @Resource
    DishService dishService;
    @GetMapping("page")
    @ApiOperation("菜品分页")
    public Result<PageResult> selectPageDish(DishPageQueryDTO dto){
        Result<PageResult> pageResultResult = dishService.selectPageCategory(dto);
        return pageResultResult;
    }
    @GetMapping("/list")
    @ApiOperation("分类id查询菜品")
    public Result<List<DishSelectIdVO>> selectIdDish(@RequestParam Integer categoryId){
        log.info("前端传过来的分类查询Id:{}",categoryId);
        List<DishSelectIdVO> dishSelectIdVOS = dishService.selectId(categoryId);
        return Result.success(dishSelectIdVOS);
    }

    @PostMapping
    @ApiOperation("新增菜品")
    public Result insertDish(@RequestBody DishDTO dto){
        log.warn("新增菜品传过来的数据{}",dto);
        int i = dishService.insertDish(dto);
        log.info("新增的菜品:{}",i);
        return Result.success(i);
    }
    @GetMapping("{id}")
    @ApiOperation("根据id查询菜品")
    public Result selectDishAll(@PathVariable Long id){
        DishVO dishVO = dishService.selectDishAll(id);
        return Result.success(dishVO);
    }
    @PutMapping()
    @ApiOperation("修改菜品")
    public Result updateDishAll(@RequestBody DishDTO dto){
        int i = dishService.updateDishAll(dto);
        return Result.success(i);
    }

    @DeleteMapping
    @ApiOperation("菜品批量删除")
    public Result deleteDishAll(@RequestParam("ids") List<Long> ids){
        int i = dishService.deletByIdDishAll(ids);
        return Result.success(i);
    }
}
